﻿
using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Personal.Servers
{
    public class NotifyServers
    {
	    private readonly IRepository<notify> notifyRepository;

        public NotifyServers()
        {
            notifyRepository = new DapperRepository<notify>();

        }

        public List<notify> GetData(   string   send_time,string  type_id
                   )
        {
            var datas = notifyRepository.GetAllEnumerable();

				 if (!string.IsNullOrEmpty(send_time)){
					 datas=datas.Where(m => m.SEND_TIME == DateTime.Parse( send_time));
					 }
                 if (!string.IsNullOrEmpty(type_id)){
					 datas=datas.Where(m => m.TYPE_ID == type_id);
					 }
                   			return datas.ToList();
        }

        public notify GetModelById(string id)
        {
            return notifyRepository.GetById(id);
        }

		
        internal void Add(notify model)
        {
            notifyRepository.Insert(model);
        }

        internal void Update(notify model)
        {
            notifyRepository.Update(model);
        }

		internal void Del(string id)
        {
            notifyRepository.DeleteByIds(id);
        }

				      
        internal List<SelectListItem> GetTYPE_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = notifyRepository.SqlWithParamsDynamic("select CODE_NO Value, concat(CODE_NO, '-----', CODE_NAME) Text  from[dbo].[sys_code] where PARENT_NO = 142");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }

        internal object GetData()
        {
            throw new NotImplementedException();
        }
    }
}